package com.hnkywl.sts.action.organ;

import com.hnkywl.sts.entity.organ.Qyjg;
import com.hnkywl.sts.service.organ.JhdwService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created with IntelliJ IDEA.
 * User: lenovo
 * Date: 13-6-5
 * Time: 上午10:58
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/organ/jhdw")
public class JhdwAction extends SimpleActionSupport {
    private JhdwService jhdwService;
    private Qyjg  jhdw;
    private Long  jhdwId;
    //企业机构名称
    private String qc;
    private String jc;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;
    //行索引
    private int index;
    private String lxr;
    private String lxrxm;
    private Long  lxrId;
    //远程ajax验证的值
    private String validateVal;
    //需要远程ajax验证的属性
    private String validateField;

    @Action("jhdwList")
    public void jhdwList() {
        this.renderJson(this.jhdwService.findAllJhdw(qc,jc,lxr,page, rows));
    }
     //判断修改 添加跳转
    @Action("jhdw_content")
    public String jhdwContent() {
        if (jhdwId != null){
            jhdw = jhdwService.findJhdwDetail(jhdwId);
        }
        return SUCCESS;
    }


    /**
     * 保存计划单位
     */
    @Action("add_jhdw")
    public void addJhdw() {
        try {
            this.jhdwService.saveJhdw(jhdw);
            renderText("{\"statusCode\":\"200\", \"message\":\"添加计划单位成功！\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }
    /**
     * 修改计划单位
     */
    @Action("update_jhdw")
    public void updateZjgl() {
        try {
            this.jhdwService.updateJhdw(jhdw);
            renderText("{\"statusCode\":\"200\",\"message\":\"修改计划单位成功！\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }
    /**
     * 删除计划单位
     */
    @Action("delete_jhdw")
    public void deleteJhdw() {
        try {
            this.jhdwService.deleteJhdw(jhdwId);
            renderText("{\"statusCode\":\"200\", \"message\":\"删除计划单位成功！\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }
    /**
     * 远程ajax验证
     */
    @Action("ajax_validate")
    public void validate1() {
        if (!jhdwService.ajaxValidate(jhdwId, validateVal, validateField))
            renderJson("{\"valid\":true}");
        else
            renderJson("{\"valid\":false}");
    }

    /**
     * 方法名:     start_jhdw
     * 功能描述:      启用计划单位
     */
    @Action("start_jhdw")
    public void startJhdw() {
        try {
            this.jhdwService.startJhdw(jhdwId);
            renderJson("{\"statusCode\":\"200\", \"message\":\"启用成功\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderJson("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 方法名:     stop_jhdw
     * 功能描述:      停用计划单位
     * 输入参数:
     */
    @Action("stop_jhdw")
    public void stopjhdw() {
        try {
            this.jhdwService.stopJhdw(jhdwId);
            renderJson("{\"statusCode\":\"200\", \"message\":\"停用成功\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderJson("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    //===========getter=======setter======================
    public String getJc() {
        return jc;
    }

    public void setJc(String jc) {
        this.jc = jc;
    }

    public String getLxrxm() {
        return lxrxm;
    }

    public void setLxrxm(String lxrxm) {
        this.lxrxm = lxrxm;
    }

    public Long getLxrId() {
        return lxrId;
    }

    public void setLxrId(Long lxrId) {
        this.lxrId = lxrId;
    }

    public String getValidateVal() {
        return validateVal;
    }

    public void setValidateVal(String validateVal) {
        this.validateVal = validateVal;
    }

    public String getValidateField() {
        return validateField;
    }

    public void setValidateField(String validateField) {
        this.validateField = validateField;
    }

    public Qyjg getJhdw() {
        return jhdw;

    }

    public void setJhdw(Qyjg jhdw) {
        this.jhdw = jhdw;
    }

    public Long getJhdwId() {
        return jhdwId;
    }

    public void setJhdwId(Long jhdwId) {
        this.jhdwId = jhdwId;
    }

    public String getLxr() {
        return lxr;
    }

    public void setLxr(String lxr) {
        this.lxr = lxr;
    }

    public String getQc() {
        return qc;
    }

    public void setQc(String qc) {
        this.qc = qc;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    @Autowired
    public void setJhdwService(JhdwService jhdwService) {
        this.jhdwService = jhdwService;
    }
}
